package nowcoder;
/**
 * 连续最大和
 * https://www.nowcoder.com/practice/5a304c109a544aef9b583dce23f5f5db?tpId=85&&tqId=29858&rp
 * =1&ru=/activity/oj&qru=/ta/2017test/question-ranking
 */
import java.util.*;
public class Day05_2 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] s = new int[n];
        for (int i = 0; i < s.length; i++) {
            s[i] = input.nextInt();
        }

        int max = s[s.length - 1];
        int sum = 0;
        for (int i = 0; i < s.length-1; i++) {
            if(s[i] < 0 && s[i] < s[i+1]){
                sum = 0;
                continue;
            }else{
                sum += s[i];
                max = Math.max(max, sum);
            }
        }
        System.out.println(max);
    }

    // 动态规划
    public static void main2(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i ++) {
            arr[i] = input.nextInt();
        }
        input.close();

        // dp[i]表示截至到下标为i处的最大和
        int[] dp = new int[n];
        // 初始化
        dp[0] = arr[0];
        int sum = arr[0];
        // 开始动规
        for(int i = 1; i < dp.length; i++) {
            sum = Math.max(sum + arr[i], arr[i]);
            dp[i] = Math.max(dp[i-1], sum);
        }
        System.out.println(dp[n-1]);
    }
}
